package cn.ml.gaoJi.api.equals;

public class EqualsTest2 {
    private int sid;
    private String name;
    private int age;

    public EqualsTest2() {
    }

    public EqualsTest2(int sid, String name, int age) {
        this.sid = sid;
        this.name = name;
        this.age = age;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //重写equals
    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if(!(obj instanceof EqualsTest2)){//判断obj属不属于Student类的对象
            return false;
        }
        EqualsTest2 s = (EqualsTest2) obj;
        if(this.sid == s.sid && this.name.equals(s.name)){
        //if (this == s){
            return true;
        }else {
            return false;
        }

    }
    public static void main(String[] args) {

        EqualsTest2 s1 = new EqualsTest2(3,"张三",18);
        EqualsTest2 s2 = new EqualsTest2(3,"张三",18);
        String s3 = "哈哈";
        System.out.println("不重写比较的是地址(==)："+(s1==s2));
        System.out.println("重写后比较类型及属性："+s1.equals(s2));
        System.out.println(s1.name.equals(s3));



    }



}
